import {
  NextResponse,
  type NextFetchEvent,
  type NextRequest,
} from 'next/server'

export function middleware(req: NextRequest, ev: NextFetchEvent) {
  const token = req.headers.get('Authorization')?.split(' ')[1]
  const url = req.nextUrl
  if (!token && !url.pathname.startsWith('')) {
    return new Response(JSON.stringify({ message: 'Unauthorized' }), {
      status: 401,
      headers: {
        'Content-Type': 'application/json',
      },
    })
  }
  // if (req.nextUrl.pathname.startsWith('/firstpage')) {
  //   url.pathname = '/imgs'
  //   return NextResponse.redirect(url)
  // }
  return NextResponse.next()
}
